package com.dog.framework.core.exception;


import com.dog.framework.core.utils.I18nUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * 基础异常
 *
 * @author ruoyi
 */
@Getter
@AllArgsConstructor
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 所属模块
     */
    private String module;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误消息key
     */
    private String msgKey;

    /**
     * 错误码对应的参数
     */
    private Object[] args;




    public BaseException(String module, Integer code, String msgKey) {
        this(module, code, msgKey, null);
    }

    public BaseException(Integer code, String msgKey) {
        this(null, code, msgKey, null);
    }

    public BaseException(String module,String msgKey,Object[] args) {
        this(module, null, msgKey, args);
    }

    public BaseException(String msgKey,Object[] args) {
        this(null, null, msgKey, args);
    }

    public BaseException(String module,String msgKey) {
        this(module, null, msgKey, null);
    }

    public BaseException(String msgKey) {
        this(null, null, msgKey, null);
    }



    @Override
    public String getMessage() {
        String message = null;
        if (!StringUtils.isEmpty(msgKey)) {
            message = I18nUtils.message(msgKey, args);
        }
        if (message == null) {
            message = msgKey;
        }
        return message;
    }

}
